<template>
    <view>
        <view class="main">
            <view class="up">
                <image mode="widthFix" src="/static/worktrain/home.jpg" />
            </view>
            <view class="down">
                <view class="menu shadow-project">
                    <block v-for="(item, index) in courseList" :key="index">
                        <view @tap="handleUrl" :data-url="'/pages/meet/index/meet_index?id=' + item.id" class="item"
						@click="go(item)">
                            <view class="item-inner">
                                <view class="img">
                                    <image :src="item.cover" />
                                </view>
                                <view class="title">{{ item.name }}</view>
                            </view>
                        </view>
                    </block>
                </view>

                <view class="area shadow-project">
                    <view class="hot-line" @tap="handleUrl" data-url="../../meet/index/meet_index?id=1">
                        <view class="left">
                            <view class="icon-left"></view>
                            热门推荐
                        </view>
                    </view>

                    <view v-if="!teacherList" class="margin-top load loading text-l load-project"></view>

                    <!-- 横向拖动 Begin -->
                    <view class="scroll-x">
                        <scroll-view :scroll-x="true" class="comm-list-scroll">
                            <view class="item-scroll" @tap="handleUrl" :data-url="'/pages/meet/detail/meet_detail?id=' + item.teacherId" v-for="(item, index) in teacherList" :key="index">
                                <image :lazy-load="true" class="loading shadow" :src="item.avatar" mode="aspectFill"></image>

                                <view class="title text-cut">{{ item.name }}</view>
                            </view>
                        </scroll-view>
                    </view>
                    <!-- 横向拖动 END -->
                </view>
				
				<!-- 通知部分 -->
                <view class="area shadow-project">
                    <view class="hot-line">
                        <view class="left">
                            <view class="icon-left"></view>
                            最新通知
                        </view>
                    </view>

                    <!-- List Begin -->
                    <view v-if="!newsList" class="margin-top load loading text-l load-project"></view>

                    <view v-else class="comm-list-box sub-margin-bottom">
                        <block v-for="(item, index) in newsList" :key="index">
                            <view class="item item-leftbig1" @tap="handleUrl" :data-url="'/pages/news/detail/news_detail?id=' + item.id">
                                <image mode="aspectFill" :lazy-load="true" class="leftbig-left loading shadow" :src="item.cover"></image>
                                <view class="leftbig-right">
                                    <view class="leftbig-title content-cut-one">{{ item.title }}</view>
                                    <view class="leftbig-desc">
                                        <text class="content-cut-two">{{ item.intro }}</text>
                                    </view>
                                    <view class="data">
                                        <view class="bottom-tag-list text-cut"></view>
                                        <view class="bottom-status">{{ item.publishTime }}</view>
                                    </view>
                                </view>
                            </view>
                        </block>
                    </view>
                    <!-- List END -->
                </view>
            </view>
        </view>

        <block v-if="skin.IS_SUB">
            <!-- parse <template is="menuTpl" :data="curMenu:'home_index',returnHome:false"/> -->
            <block name="menuTpl">
                <view class="tab-bar">
                    <view v-if="false" class="tab-bar-home" @tap="handleUrl" data-type="relaunch" data-url="/pages/home/index/home_index">
                        <text class="tab-bar-home-text icon-homefill text-grey"></text>
                    </view>

                    <view class="tab-bar-border"></view>
                    <view class="tab-bar-item" @tap="handleUrl" data-type="relaunch" data-url="/projects/worktrain/pages/default/index/default_index">
                        <image class="tab-icon" :src="'/projects/worktrain/images/tabbar/home' + ('home_index' == 'home_index' ? '_cur' : '') + '.png'"></image>
                        <view :class="'tab-text ' + ('home_index' == 'home_index' ? 'menu-project' : '')">首页</view>
                    </view>

                    <view class="tab-bar-item" @tap="handleUrl" data-type="relaunch" data-url="/projects/worktrain/pages/news/index/news_index">
                        <image class="tab-icon" :src="'/projects/worktrain/images/tabbar/news' + ('home_index' == 'news_index' ? '_cur' : '') + '.png'"></image>
                        <view :class="'tab-text ' + ('home_index' == 'news_index' ? 'menu-project' : '')">公告通知</view>
                    </view>

                    <view v-if="skin.cate2 !== false" class="tab-bar-item" @tap="handleUrl" data-type="relaunch" data-url="/projects/worktrain/pages/meet/calendar/meet_calendar">
                        <image class="tab-icon" :src="'/projects/worktrain/images/tabbar/day' + ('home_index' == 'meet_calendar' ? '_cur' : '') + '.png'"></image>
                        <view :class="'tab-text ' + ('home_index' == 'meet_calendar' ? 'menu-project' : '')">预约日历</view>
                    </view>

                    <view class="tab-bar-item" @tap="handleUrl" data-type="relaunch" data-url="/projects/worktrain/pages/my/index/my_index">
                        <image class="tab-icon" :src="'/projects/worktrain/images/tabbar/my' + ('home_index' == 'my_index' ? '_cur' : '') + '.png'"></image>
                        <view :class="'tab-text ' + ('home_index' == 'my_index' ? 'menu-project' : '')">个人中心</view>
                    </view>
                </view>
            </block>
        </block>
    </view>
</template>

<script>
	// import mixin from '@/utils/mixin.js';
// const pageHelper = require('../../../../../helper/page_helper.js');
// const cloudHelper = require('../../../../../helper/cloud_helper.js');
// const ProjectBiz = require('../../../biz/project_biz.js');
// const projectSetting = require('../../../public/project_setting.js');
const pageHelper = require('@/utils/helper/page_helper.js');
const cloudHelper = require('@/utils/helper/cloud_helper.js');
const ProjectBiz = require('@/utils/biz/project_biz.js');
const projectSetting = require('@/utils/public/project_setting.js');
const api = require('@/api/api.js');

export default {
    data() {
        return {
            cateList: '',
            meetList: '',
            newsList: '',
            courseList: '',
            teacherList: '',
            skin: {
                IS_SUB: '',
                cate2: false
            }
        };
    }
    /**
     * 生命周期函数--监听页面加载
     */,
    onLoad: async function (options) {
        ProjectBiz.initPage(this);
        // this.setData({
        //     cateList: projectSetting.MEET_CATE
        // });
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {},
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: async function () {
        this.loadListFun();
    },
    onPullDownRefresh: async function () {
        await this.loadListFun();
        uni.stopPullDownRefresh();
    },
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {},
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {},
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {},
    methods: {
        loadListFun: async function () {
            let opts = {
                title: 'bar'
            };
            await api.getHomeInfo({}).then((res) => {
                console.log(res);
                this.courseList = res.courses;
                this.teacherList = res.teachers;
                this.newsList = res.notices;
            });
            // await cloudHelper.callCloudSumbit('home/list', {}, opts).then((res) => {
            //     this.setData({
            //         ...res.data
            //     });
            // });
            // 课程列表
            //  await api.getCourseList({
            //    // page: 1,
            //    // size: 10
            //  }).then((data) => {
            //    this.courseList = data;
            //  }).catch((error) => {
            //    console.error('获取课程列表失败:', error);
            //    uni.showToast({
            //      title: '获取课程列表失败',
            //      icon: 'none'
            //    });
            //  });

            //  // 教师热门推荐列表
            //  await api.getTeacherList({
            //    // page: 1,
            //    // size: 10
            //  }).then((data) => {
			// 	// debugger
            //    this.teacherList = data;
            //  }).catch((error) => {
            //    console.error('获取教师列表失败:', error);
            //    uni.showToast({
            //      title: '获取教师列表失败',
            //      icon: 'none'
            //    });
            //  });
			 
			//  // 公告通知列表
			//  await api.getNoticeList({
			//    // page: 1,
			//    // size: 10
			//  }).then((data) => {
			//    this.newsList = data;
			//  }).catch((error) => {
			//    console.error('获取公告通知列表失败:', error);
			//    uni.showToast({
			//      title: '获取公告通知列表失败',
			//      icon: 'none'
			//    });
			//  });
        },

		go: function(item) {
			// let page = '/pages/convert/convert'
			// if(i.task === 'img2pdf'){
			// 	page = '/pages/img2pdf/imgmerge'
			// }else if(i.task === 'pdf2word'){
			// 	page = '/pages/convert/convert'
			// }else if(i.task === 'pdfmerge'){
			// 	page = '/pages/pdf2merge/pdf2merge'
			// }else if(i.task === 'imgmerge'){
			// 	// page = '/pages/img2pdf/imagetest'
			// 	page = '/pages/img2pdf/imgmerge'
			// }
			console.log(111);
			let str = '/meet/index/meet_index?id=' + item.id;
			uni.navigateTo({
				url: str
			});
		},

      handleUrl: async function (e) {
            pageHelper.url(e, this);
        }
    }
};
</script>
<style>
@import './default_index.css';
/* @import 'undefined'; */
</style>
